<?php

class ShellComponent extends Object {
   
    private $cakeConsole;

    public function startup() {
        $this->cakeConsole = ROOT . DS . 'cake' . DS . 'console' . DS . 'cake';
    }

    public function run($shell, $background = false, $params = array()) {
        //Build command
        $cmd = array($shell);
       
        $pre = '';

        //Params
        foreach($params as $key => $val) {
            $cmd[] = '-' . $key . ' ' . '"' . $val . '"';
        }
        $cmd[] = '-app' . ' ' . APP;

        //Background
        if($background == true) {
            $pre .= 'nohup';
        }

        $cmd = $pre . ' ' . $this->cakeConsole . ' ' . implode(' ', $cmd);
        return shell_exec($cmd);
    }
}